//
//  CSL_PlayerPage_ViewController.m
//  HZ_Beautiful_Music
//
//  Created by dllo on 16/4/8.
//  Copyright © 2016年 ui. All rights reserved.
//

#import "CSL_PlayerPage_ViewController.h"
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
#import "CSLPlayer.h"
#import "HZ_play_hs_Model.h"
#import "HZ_url_hs_Model.h"
#import <UIImageView+WebCache.h>
@interface CSL_PlayerPage_ViewController ()
@property (nonatomic, strong) UIButton *backButton;//返回按钮
@property (nonatomic, strong) UILabel *titleLabel;//标题
@property (nonatomic, strong) UIButton *listButton;//菜单按钮
@property (nonatomic, strong) UILabel *biaozhunLabel;//标准
@property (nonatomic, strong) UILabel *nameLabel;//姓名
@property (nonatomic, strong) UILabel *playedLabel;//播放的时间
@property (nonatomic, strong) UIButton *UnknownButton;
@property (nonatomic, strong) UILabel *totalTimeLabel;//总时间
@property (nonatomic, strong) UIButton *cycleButton;//循环按钮
@property (nonatomic, strong) UIButton *frontButton;//上一曲按钮
@property (nonatomic, strong) UIButton *playButton;//播放按钮
@property (nonatomic, strong) UIButton *nextButton;//下一曲按钮
@property (nonatomic, strong) UIButton *musicListButton;//音乐菜单
@property (nonatomic, strong) CAGradientLayer *gradientLayer;//渐变色
@property (nonatomic, strong) CAGradientLayer *gradientLayer1;//渐变色
@property (nonatomic, strong) CSLPlayer *playerTwo;
@property (nonatomic, strong) NSTimer *avTimer;
@property (nonatomic, assign) BOOL isplay;
@property (nonatomic, assign) NSInteger hsinteger;
@property (nonatomic, assign) NSInteger hsintegrTwo;
@property (nonatomic, assign) BOOL isdanqu;
@property (nonatomic, assign) BOOL issuijibofang;
@property (nonatomic, strong) UIImageView *cslimageView;
@end

@implementation CSL_PlayerPage_ViewController
-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}
+(instancetype)playViewController {
    
    static CSL_PlayerPage_ViewController *playviewController = nil;
    static dispatch_once_t play;
    
    dispatch_once(&play, ^{
        
        playviewController = [[CSL_PlayerPage_ViewController alloc] init];
        
    });
    return playviewController;
}
- (void)viewDidLoad {
    [super viewDidLoad];
     self.playerTwo = [CSLPlayer shareAVPlayer];
    self.cslimageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
//    self.cslimageView.image = [UIImage imageNamed:@"Music"];
    [self.view addSubview:self.cslimageView];
    self.gradientLayer = [CAGradientLayer layer];
    _gradientLayer.frame = CGRectMake(0, self.view.bounds.size.height / 2, self.view.bounds.size.width, self.view.bounds.size.height / 2) ;
    [self.cslimageView.layer addSublayer:_gradientLayer];
 
    _gradientLayer.startPoint = CGPointMake(0, 0);
    _gradientLayer.endPoint = CGPointMake(0, 3.5);
    _gradientLayer.colors = @[(__bridge id)[UIColor clearColor].CGColor,(__bridge id)[UIColor blackColor].CGColor];
    _gradientLayer.locations = @[@(0.1f),@(0.3f)];

    [self CreateHeadSpace];
    [self CreateSlider];
    [self CreateCurrentTimeLabel];
    [self CreateBottomControl];
    NSNotificationCenter *hsarray = [NSNotificationCenter defaultCenter];
    [hsarray addObserver:self selector:@selector(hsarray:) name:@"hsarray" object:nil];

    NSNotificationCenter *hsplaybuttonTwo = [NSNotificationCenter defaultCenter];
    [hsplaybuttonTwo addObserver:self selector:@selector(hsplaybuttonTwo:) name:@"hsplaybuttonTwo" object:nil];
    
    NSNotificationCenter *hspausebuttonTwo = [NSNotificationCenter defaultCenter];
    [hspausebuttonTwo addObserver:self selector:@selector(hspausebuttonTwo:) name:@"hspausebuttonTwo" object:nil];
    
    NSNotificationCenter *hsstrnitem = [NSNotificationCenter defaultCenter];
    [hsstrnitem addObserver:self selector:@selector(hsstrnitem:) name:@"hsstrnitem" object:nil];
    if (_playerTwo.isbutton) {
        [_playButton setBackgroundImage:[[UIImage imageNamed:@"cslzanting"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        _isplay = YES;
        _playerTwo.isbutton = NO;
    }
    
   
    
}



//最大时间值
-(void)hsstrnitem:(NSNotification *)hsstrnitem{
    
    NSArray *arrr = [NSArray arrayWithArray:hsstrnitem.object];
    
    _totalTimeLabel.text = arrr[0];
//    _titleLabel.text = arrr[1];
//    _nameLabel.text = arrr[2];
//    [_cslimageView sd_setImageWithURL:[NSURL URLWithString:arrr[3]]];
}
-(void)hspausebuttonTwo:(NSNotification *)hspausebuttonTwo{
    [_playButton setBackgroundImage:[[UIImage imageNamed:@"cslplay"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    _isplay = NO;
}
-(void)hsplaybuttonTwo:(NSNotification *)hsplaybuttonTwo{

    [CSLPlayer shareAVPlayer].isbutton = NO;

    NSLog(@"play");

    
    [CSLPlayer shareAVPlayer].isbutton = NO;


    [_playButton setBackgroundImage:[[UIImage imageNamed:@"cslzanting"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    _isplay = YES;
}
//item
-(void)hsarray:(NSNotification *)hsarray{

    if (_playerTwo.isbutton) {
        [_playButton setBackgroundImage:[[UIImage imageNamed:@"cslzanting"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        _isplay = YES;
        _playerTwo.isbutton = NO;
    }
    NSArray *array = hsarray.object;
    
    NSString *str = array[0];
    _titleLabel.text = array[1];
    _nameLabel.text = array[2];
    
    if (array[3]) {
        [_cslimageView sd_setImageWithURL:[NSURL URLWithString:array[3]]];
        
    } else {
        
      _cslimageView.image = [UIImage imageNamed:@"32"];

    }

    _hsinteger = str.integerValue;
     NSLog(@"%@", array[3]);
    NSLog(@"%ld", (long)_hsinteger);
}
#pragma mark - 创建头部控件，包含返回按钮、标题、菜单、标准、姓名
-(void)CreateHeadSpace {
    self.backButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _backButton.frame = CGRectMake(self.view.bounds.size.width/30, self.view.bounds.size.height/30, self.view.bounds.size.width/15, self.view.bounds.size.height/25);
//    _backButton.backgroundColor = [UIColor redColor];
    [_backButton setImage:[[UIImage imageNamed:@"gobackBtn"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [_backButton addTarget:self action:@selector(BackButtonAction:) forControlEvents: UIControlEventTouchUpInside];
    [self.view addSubview:_backButton];

    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/7, self.view.bounds.size.height/30, 4 * self.view.bounds.size.width/5, self.view.bounds.size.height/25)];
//    _titleLabel.backgroundColor = [UIColor redColor];
    _titleLabel.font = [UIFont systemFontOfSize:20];
    _titleLabel.textColor = [UIColor whiteColor];
//    _titleLabel.text = [CSLPlayer shareAVPlayer].name;
    [self.view addSubview:_titleLabel];
    
    self.listButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _listButton.frame = CGRectMake(self.view.bounds.size.width/1.1, self.view.bounds.size.height/30, self.view.bounds.size.width/20, self.view.bounds.size.height/30);
//    _listButton.backgroundColor = [UIColor redColor];
    [_listButton setImage:[[UIImage imageNamed:@"csllist"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:_listButton];
    
    self.biaozhunLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/7, self.view.bounds.size.height/12, self.view.bounds.size.width/10, self.view.bounds.size.height/35)];
//    _biaozhunLabel.backgroundColor = [UIColor redColor];
    _biaozhunLabel.text = @"标准";
    _biaozhunLabel.textAlignment = NSTextAlignmentCenter;
    _biaozhunLabel.textColor = [UIColor colorWithRed:0.176 green:0.757 blue:0.198 alpha:1.000];
    _biaozhunLabel.font = [UIFont systemFontOfSize:13];
    //    设置圆角
    [_biaozhunLabel.layer setCornerRadius:10];
    _biaozhunLabel.layer.masksToBounds = YES;
    //    然后再给图层添加一个有色的边框
    _biaozhunLabel.layer.borderWidth = 1;
    _biaozhunLabel.layer.borderColor = [[UIColor colorWithRed:0.190 green:0.806 blue:0.180 alpha:1.000] CGColor];
    [self.view addSubview:_biaozhunLabel];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/4, self.view.bounds.size.height/12, self.view.bounds.size.width/3, self.view.bounds.size.height/35)];
//    _nameLabel.text = [CSLPlayer shareAVPlayer].singerName;
    _nameLabel.textColor = [UIColor whiteColor];
    _nameLabel.font = [UIFont systemFontOfSize:15];
//    _nameLabel.backgroundColor = [UIColor redColor];
    
        HZ_play_hs_Model *playModel = _array[_hsinteger];
    
        _titleLabel.text = playModel.name;
    
        _nameLabel.text = playModel.singerName;
    [self.view addSubview:_nameLabel];
    
    self.avTimer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(timer) userInfo:nil repeats:YES];
}
-(void)timer{

    self.slider.value = CMTimeGetSeconds(self.playerTwo.currentItem.currentTime) / CMTimeGetSeconds(self.playerTwo.currentItem.duration);
    NSInteger tot = CMTimeGetSeconds(self.playerTwo.currentItem.currentTime);
    NSInteger min = tot / 60;
    NSInteger sec = tot % 60;
    NSString *time = [NSString stringWithFormat:@"%02ld : %02ld", (long)min, (long)sec];
    _playedLabel.text = time;
    if (self.slider.value == 1 && _hsinteger <= _array.count - 1) {
        NSLog(@"~~~~%f", self.slider.value);
        if (_isdanqu == NO && _issuijibofang == YES) {
            
            NSLog(@"%ld", (long)_hsinteger);
            HZ_play_hs_Model *playModel = _array[_hsinteger];
            _titleLabel.text = playModel.name;
            _nameLabel.text = playModel.singerName;
            [_cslimageView sd_setImageWithURL:[NSURL URLWithString:playModel.picUrl]];
            HZ_url_hs_Model *url = playModel.auditionList[1];
            
            NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
            
            int item = str.intValue;
            if (item >= 600) {
                _totalTimeLabel.text = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
            } else {
                _totalTimeLabel.text = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
            }
            self.playerTwo = [CSLPlayer shareAVPlayer];
            
            [_playerTwo playWithUrl:url.url];
            [_playButton setBackgroundImage:[[UIImage imageNamed:@"cslzanting"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
            [self.playerTwo play];
            _isplay = YES;
            
            NSNotificationCenter *hsitemButton = [NSNotificationCenter defaultCenter];
            
            NSString *strr = [NSString stringWithFormat:@"%ld", (long)_hsinteger];
            [hsitemButton postNotificationName:@"hsitemButton" object:strr userInfo:nil];
        } else if (_issuijibofang == NO && _hsinteger <= _array.count - 1) {
         
            _hsinteger = arc4random()%_array.count;
            
            NSLog(@"!!!!!%ld", (long)_hsinteger);
            
            HZ_play_hs_Model *playModel = _array[_hsinteger];
            _titleLabel.text = playModel.name;
            _nameLabel.text = playModel.singerName;
            [_cslimageView sd_setImageWithURL:[NSURL URLWithString:playModel.picUrl]];
            HZ_url_hs_Model *url = playModel.auditionList[1];
            
            NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
            
            int item = str.intValue;
            if (item >= 600) {
                _totalTimeLabel.text = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
            } else {
                
                _totalTimeLabel.text = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
                
            }
            self.playerTwo = [CSLPlayer shareAVPlayer];
            
            [_playerTwo playWithUrl:url.url];
            [_playButton setBackgroundImage:[[UIImage imageNamed:@"cslzanting"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
            [self.playerTwo play];
            _isplay = YES;
          
            NSNotificationCenter *hsitemButton = [NSNotificationCenter defaultCenter];
            
            NSString *strr = [NSString stringWithFormat:@"%ld", (long)_hsinteger];
            [hsitemButton postNotificationName:@"hsitemButton" object:strr userInfo:nil];
        } else if (_isdanqu && _issuijibofang && _hsinteger <= _array.count - 1){
            
            
            _hsinteger += 1 ;
            if (_hsinteger == _array.count) {
                _hsinteger = 0;
            }
            NSLog(@"#####%ld", (long)_hsinteger);
            HZ_play_hs_Model *playModel = _array[_hsinteger];
            _titleLabel.text = playModel.name;
            _nameLabel.text = playModel.singerName;
            [_cslimageView sd_setImageWithURL:[NSURL URLWithString:playModel.picUrl]];
            HZ_url_hs_Model *url = playModel.auditionList[1];
            
            NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
            
            int item = str.intValue;
            if (item >= 600) {
                _totalTimeLabel.text = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
            } else {
                
                _totalTimeLabel.text = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
                
            }
            self.playerTwo = [CSLPlayer shareAVPlayer];
            
            [_playerTwo playWithUrl:url.url];
            [_playButton setBackgroundImage:[[UIImage imageNamed:@"cslzanting"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
            [self.playerTwo play];
            _isplay = YES;
            
            NSNotificationCenter *hsitemButton = [NSNotificationCenter defaultCenter];
            
            NSString *strr = [NSString stringWithFormat:@"%ld", (long)_hsinteger];
            [hsitemButton postNotificationName:@"hsitemButton" object:strr userInfo:nil];
        }
    }
}

#pragma mark - 创建UISlider
-(void)CreateSlider{
    self.slider = [[UISlider alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/6, self.view.bounds.size.height/1.2, self.view.bounds.size.width/1.45, 2)];
    [_slider setThumbImage:[[UIImage imageNamed:@"yuan"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [_slider addTarget:self action:@selector(progressSlider:) forControlEvents:UIControlEventValueChanged];
    _slider.minimumTrackTintColor = [UIColor colorWithRed:0.848 green:0.261 blue:0.118 alpha:1.000];
    [self.view addSubview:_slider];
}
#pragma mark - slider滑动时间
-(void)progressSlider:(UISlider *)slider {
    [self.playerTwo seekToTime:CMTimeMakeWithSeconds(self.playerTwo.currentItem.duration.value / self.playerTwo.currentItem.duration.timescale * self.slider.value, self.playerTwo.currentTime.timescale) completionHandler:^(BOOL finished) {
//        [self.playerTwo play];
    }];
}
#pragma mark - 创建播放时间
-(void)CreateCurrentTimeLabel{
    self.playedLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/45, self.view.bounds.size.height/1.22, self.view.bounds.size.width / 7, self.view.bounds.size.height/35)];
    _playedLabel.textColor = [UIColor colorWithWhite:0.922 alpha:1.000];
    _playedLabel.font = [UIFont systemFontOfSize:12];
    _playedLabel.textAlignment = NSTextAlignmentCenter;
    _playedLabel.text = @"00:00";
//    _playedLabel.backgroundColor = [UIColor redColor];
    [self.view addSubview:_playedLabel];
    
    self.totalTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/1.15, self.view.bounds.size.height/1.22, self.view.bounds.size.width/8, self.view.bounds.size.height/35)];
    _totalTimeLabel.textColor = [UIColor colorWithWhite:0.922 alpha:1.000];
    _totalTimeLabel.font = [UIFont systemFontOfSize:12];
    _totalTimeLabel.textAlignment = NSTextAlignmentCenter;
    _totalTimeLabel.text = [CSLPlayer shareAVPlayer].strn;
//    _totalTimeLabel.backgroundColor = [UIColor redColor];
    [self.view addSubview:_totalTimeLabel];
}
#pragma mark - 创建底部控件包括循环、上一曲、播放、暂停、下一曲、音乐菜单
-(void)CreateBottomControl{
  //循环播放按钮
    self.cycleButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _cycleButton.frame = CGRectMake(self.view.bounds.size.width/15, self.view.bounds.size.height/1.1, self.view.bounds.size.width/15, self.view.bounds.size.height/30);
    [_cycleButton setBackgroundImage:[[UIImage imageNamed:@"cslxunhuan"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [_cycleButton addTarget:self action:@selector(AycleButton:) forControlEvents:UIControlEventTouchUpInside];
    _isdanqu = YES;
    _issuijibofang = YES;
    [self.view addSubview:_cycleButton];
  //上一曲按钮
    self.frontButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    _frontButton.backgroundColor = [UIColor redColor];
    _frontButton.frame = CGRectMake(self.view.bounds.size.width/4.8, self.view.bounds.size.height/1.11, self.view.bounds.size.width/10, self.view.bounds.size.height/25);
    [_frontButton setImage:[[UIImage imageNamed:@"cslfont"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [_frontButton addTarget:self action:@selector(frontButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_frontButton];
    
    //播放、暂停按钮
    self.playButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _playButton.frame = CGRectMake(self.view.bounds.size.width/2.3, self.view.bounds.size.height/1.12, self.view.bounds.size.width/7, self.view.bounds.size.height/14);
    [_playButton setBackgroundImage:[UIImage imageNamed:@"cslplay"] forState:UIControlStateNormal];
//    取消小蓝块
    [_playButton setTintColor:[UIColor clearColor]];
    [_playButton addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_playButton];
    
    //下一曲按钮
    self.nextButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    _nextButton.backgroundColor = [UIColor redColor];
    _nextButton.frame = CGRectMake(self.view.bounds.size.width/1.45, self.view.bounds.size.height/1.11, self.view.bounds.size.width/10, self.view.bounds.size.height/25);
    [_nextButton setImage:[[UIImage imageNamed:@"cslnext"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [_nextButton addTarget:self action:@selector(nextButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_nextButton];
    
    //音乐菜单按钮
    self.musicListButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    _musicListButton.backgroundColor = [UIColor redColor];
    _musicListButton.frame = CGRectMake(self.view.bounds.size.width/1.15, self.view.bounds.size.height/1.1, self.view.bounds.size.width/15, self.view.bounds.size.height/30);
    [_musicListButton setImage:[[UIImage imageNamed:@"cslmusiclist"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:_musicListButton];
}

-(void)AycleButton:(UIButton *)AycleButton{
    if (_isdanqu && _issuijibofang ) {
        [_cycleButton setBackgroundImage:[UIImage imageNamed:@"Unknown"] forState:UIControlStateNormal];
        _isdanqu = NO;
        
    } else if (_isdanqu == NO && _issuijibofang == YES){
        
        [_cycleButton setBackgroundImage:[UIImage imageNamed:@"Unknown-1"] forState:UIControlStateNormal];
        _issuijibofang = NO;
    }  else if (_isdanqu == NO && _issuijibofang == NO){
        [_cycleButton setBackgroundImage:[UIImage imageNamed:@"cslxunhuan"] forState:UIControlStateNormal];
        _isdanqu = YES;
        _issuijibofang = YES;
    }
}
-(void)frontButton:(UIButton *)frontButton{
    NSLog(@"%ld", (long)_hsinteger);
    if (_hsinteger == 0) {
        _hsinteger = _array.count - 1;
        HZ_play_hs_Model *playModel = _array[_hsinteger];
        _titleLabel.text = playModel.name;
        _nameLabel.text = playModel.singerName;
        [_cslimageView sd_setImageWithURL:[NSURL URLWithString:playModel.picUrl]];
        _hsinteger = _array.count - 1;
        HZ_url_hs_Model *url = playModel.auditionList[1];
        NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
        int item = str.intValue;
        if (item >= 600) {
            _totalTimeLabel.text = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
        } else {
            _totalTimeLabel.text = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
        }
        self.playerTwo = [CSLPlayer shareAVPlayer];
        [_playerTwo playWithUrl:url.url];
        [_playButton setBackgroundImage:[UIImage imageNamed:@"cslzanting"] forState:UIControlStateNormal];
        [self.playerTwo play];
        _isplay = YES;
    } else{
        _hsinteger -= 1;
        HZ_play_hs_Model *playModel = _array[_hsinteger];
        _titleLabel.text = playModel.name;
        _nameLabel.text = playModel.singerName;
        [_cslimageView sd_setImageWithURL:[NSURL URLWithString:playModel.picUrl]];
        HZ_url_hs_Model *url = playModel.auditionList[1];
        NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
        int item = str.intValue;
        if (item >= 600) {
            _totalTimeLabel.text = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
        } else {
            _totalTimeLabel.text = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
        }
        self.playerTwo = [CSLPlayer shareAVPlayer];
        [_playerTwo playWithUrl:url.url];
        [_playButton setBackgroundImage:[UIImage imageNamed:@"cslzanting"]  forState:UIControlStateNormal];
        [self.playerTwo play];
        _isplay = YES;
    }
    NSNotificationCenter *hsfrontButton = [NSNotificationCenter defaultCenter];
    NSString *str = [NSString stringWithFormat:@"%ld", (long)_hsinteger];
    [hsfrontButton postNotificationName:@"hsfrontButton" object:str userInfo:nil];
}
//下一曲
-(void)nextButton:(UIButton *)nextButton{
    if (_hsinteger == _array.count - 1) {
        HZ_play_hs_Model *playModel = _array[0];
        _titleLabel.text = playModel.name;
        _nameLabel.text = playModel.singerName;
        [_cslimageView sd_setImageWithURL:[NSURL URLWithString:playModel.picUrl]];
        HZ_url_hs_Model *url = playModel.auditionList[1];
        NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
        int item = str.intValue;
        if (item >= 600) {
            _totalTimeLabel.text = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
        } else {
            
            _totalTimeLabel.text = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
        }
        self.playerTwo = [CSLPlayer shareAVPlayer];
        [_playerTwo playWithUrl:url.url];
        [_playButton setBackgroundImage:[[UIImage imageNamed:@"cslzanting"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [self.playerTwo play];
        _hsinteger = 0;
        _isplay = YES;

    } else {
        _hsinteger += 1;
        HZ_play_hs_Model *playModel = _array[_hsinteger];
        _titleLabel.text = playModel.name;
        _nameLabel.text = playModel.singerName;
        [_cslimageView sd_setImageWithURL:[NSURL URLWithString:playModel.picUrl]];
        HZ_url_hs_Model *url = playModel.auditionList[1];
        NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
        
        int item = str.intValue;
        if (item >= 600) {
            _totalTimeLabel.text = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
        } else {
            
            _totalTimeLabel.text = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
            
        }
        self.playerTwo = [CSLPlayer shareAVPlayer];
        
        [_playerTwo playWithUrl:url.url];
        [_playButton setBackgroundImage:[[UIImage imageNamed:@"cslzanting"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [self.playerTwo play];
        _isplay = YES;
    }
    NSNotificationCenter *hsnextButton = [NSNotificationCenter defaultCenter];
    NSString *str = [NSString stringWithFormat:@"%ld", (long)_hsinteger];
    [hsnextButton postNotificationName:@"hsnextButton" object:str userInfo:nil];
}
#pragma mark - 播放、暂停按钮的点击事件
-(void)startAction:(UIButton *)button {
    if (_isplay) {
        [_playerTwo pause];
        [_playButton setBackgroundImage:[UIImage imageNamed:@"cslplay"]  forState:UIControlStateNormal];
        NSNotificationCenter *hspauseButton = [NSNotificationCenter defaultCenter];
        [hspauseButton postNotificationName:@"hspauseButton" object:nil userInfo:nil];
        _isplay = NO;
    } else{
        [_playerTwo play];
        [_playButton setBackgroundImage:[UIImage imageNamed:@"cslzanting"]  forState:UIControlStateNormal];
        NSNotificationCenter *hsplayButton = [NSNotificationCenter defaultCenter];
        [hsplayButton postNotificationName:@"hsplayButton" object:nil userInfo:nil];
        _isplay = YES;
    }
    button.selected = !button.selected;
}
//-(void)setArray:(NSMutableArray *)array{
//    
//    
//    _array = array;
////    HZ_play_hs_Model *playModel = _array[_hsinteger];
////    
////    _titleLabel.text = playModel.name;
////    
////    _nameLabel.text = playModel.singerName;
//
//}
#pragma mark - 返回按钮的点击事件
-(void)BackButtonAction:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:^{}];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
